// 节流
/**
 * 使用实例
 * window.onscroll = debounce(function(){
 * console.log('debounce')
 * },1000)
 */
export function debounce(fn, delay) {
    let timeout;
    return function () {
        let context = this; // 指向全局
        let args = arguments;
        if (timeout) {
            clearTimeout(timeout);
        }
        timeout = setTimeout(() => {
            fn.apply(context, args);
        }, delay)
    }
}